<template>
  <div>
    <h3 class="dialog-plate-title mt-1"><span>今日检测</span></h3>
    <el-button type="primary" @click="showDialog('insert')">结果上传</el-button> 
    <el-table :data="tableDataForBlood" stripe border style="width: 100%" class="company-table">
      <el-table-column fixed type="index" label="*" sortable align="center" min-width="40"></el-table-column>
      <el-table-column prop="wbc" label="白细胞计数" sortable min-width="50"></el-table-column>
      <el-table-column prop="platelet" label="血小板" sortable min-width="50"></el-table-column>
      <el-table-column prop="hct" label="HCT" sortable min-width="50"></el-table-column>
      <el-table-column prop="triglyceride" label="甘油三脂" sortable min-width="50"></el-table-column>
      <el-table-column prop="lp" label="LP" sortable min-width="50"></el-table-column>
      <el-table-column prop="sod" label="SOD" sortable min-width="50"></el-table-column>
      <el-table-column prop="mda" label="MDA" sortable min-width="50"></el-table-column>
      <el-table-column prop="ldl" label="低密脂蛋白" sortable min-width="50"></el-table-column>
      <el-table-column prop="cholesterol" label="胆固醇" sortable min-width="50"></el-table-column>
      <el-table-column prop="wholeBloodLevel" label="全血比重" sortable min-width="50"></el-table-column>
      <el-table-column prop="proteinLevel" label="蛋白含量" sortable min-width="50"></el-table-column>
      <el-table-column prop="serumProteinLevel" label="血清蛋白含量" sortable min-width="50"></el-table-column>
      <el-table-column prop="hemoglobinLevelName" label="血红蛋白含量" sortable min-width="50"></el-table-column>
      <el-table-column prop="hbsAgName" label="HBsAg" sortable min-width="50"></el-table-column>
      <el-table-column prop="hcvName" label="抗-HCV" sortable min-width="50"></el-table-column>
      <el-table-column prop="syphilisName" label="梅毒" sortable min-width="50"></el-table-column>
      <el-table-column prop="hivName" label="抗-HIV" sortable min-width="50"></el-table-column>
      <el-table-column prop="altName" label="ALT" sortable min-width="50"></el-table-column>
      <el-table-column prop="bloodTypeName" label="血型" sortable min-width="50"></el-table-column>
      <el-table-column prop="inspectionRemark" label="胆固醇" sortable min-width="50"></el-table-column>
      <el-table-column fixed="right" label="操作" align="left" min-width="75">
        <template slot-scope="scope">
          <el-button  @click="insertUpdateCheck(scope.row)" type="text" size="small">编辑</el-button>
        </template>         
      </el-table-column>
    </el-table>
    <!-- 新增详情 -->
    <el-dialog :visible.sync="dialog.open" title="院内血液检测"  width="800px" center :close-on-click-modal="false" class="bodyNopaddingTop" >
      <el-form :model="dialog.formData" label-width="100px" :inline="true">
        <el-form-item label="白细胞计数" prop="wbc"><el-input v-model="dialog.formData.wbc" class="width220" /></el-form-item>
        <el-form-item label="血小板" prop="platelet" ><el-input v-model="dialog.formData.platelet" class="width220" /></el-form-item>
        <el-form-item label="HCT" prop="hct" ><el-input v-model="dialog.formData.hct" class="width220" /> </el-form-item>
        <el-form-item label="甘油三脂" prop="triglyceride" ><el-input v-model="dialog.formData.triglyceride" class="width220" /></el-form-item>
        <el-form-item label="LP" prop="lp" ><el-input v-model="dialog.formData.lp" class="width220" /> </el-form-item>
        <el-form-item label="SOD" prop="sod" ><el-input v-model="dialog.formData.sod" class="width220" /> </el-form-item>
        <el-form-item label="MDA" prop="mda" ><el-input v-model="dialog.formData.mda" class="width220" /> </el-form-item>
        <el-form-item label="低密脂蛋白" prop="ldl" ><el-input v-model="dialog.formData.ldl" class="width220" /> </el-form-item>
        <el-form-item label="胆固醇" prop="cholesterol" ><el-input v-model="dialog.formData.cholesterol" class="width220" /> </el-form-item>
        <el-form-item label="全血比重" prop="wholeBloodLevel" >
          <el-select v-model="dialog.formData.wholeBloodLevel" class="width220" >
            <el-option label="合格" :value="1">合格</el-option>
            <el-option label="不合格" :value="0">不合格</el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="蛋白含量" prop="proteinLevel" ><el-input v-model="dialog.formData.proteinLevel" class="width220" /> </el-form-item>
        <el-form-item label="血清蛋白含量" prop="serumProteinLevel" ><el-input v-model="dialog.formData.serumProteinLevel" class="width220" /> </el-form-item>
        <el-form-item label="血红蛋白含量" prop="hemoglobinLevel" >
          <el-select v-model="dialog.formData.hemoglobinLevel" class="width220">
            <el-option v-for="item in hemoglobinLevelList" :key="item.code" :label="item.name" :value="item.code" />
          </el-select> 
        </el-form-item>
        <el-form-item label="HBsAg" prop="hbsAg" >
          <el-select v-model="dialog.formData.hbsAg" class="width220" >
            <el-option label="阴性" :value="1">阴性</el-option>
            <el-option label="阳性" :value="0">阳性</el-option>
          </el-select>  
        </el-form-item>
        <el-form-item label="抗-HCV" prop="hcv" >         
          <el-select v-model="dialog.formData.hcv" class="width220" >
            <el-option label="阴性" :value="1">阴性</el-option>
            <el-option label="阳性" :value="0">阳性</el-option>
          </el-select>     
        </el-form-item>
        <el-form-item label="梅毒" prop="syphilis" >
          <el-select v-model="dialog.formData.syphilis" class="width220" >
            <el-option label="阴性" :value="1">阴性</el-option>
            <el-option label="阳性" :value="0">阳性</el-option>
          </el-select> 
        </el-form-item>
        <el-form-item label="抗-HIV" prop="hiv" ><el-input v-model="dialog.formData.hiv" class="width220" /></el-form-item>
        <el-form-item label="ALT" prop="alt" >
          <el-select v-model="dialog.formData.alt" class="width220">
            <el-option v-for="item in ALTResultList" :key="item.code" :label="item.name" :value="item.code" />
          </el-select> 
        </el-form-item>
        <el-form-item label="血型" prop="bloodType" >
          <el-select v-model="dialog.formData.bloodType" class="width220">
            <el-option v-for="item in bloodTypeList" :key="item.code" :label="item.name" :value="item.code" />
          </el-select> 
        </el-form-item>
        <el-form-item label="化检备注" prop="inspectionRemark" class="form-item-block"><el-input type="textarea" v-model="dialog.formData.inspectionRemark" class="width520" /></el-form-item>
        <el-form-item label="检测日期" prop="assayTime" ><el-date-picker type="date" v-model="dialog.formData.assayTime" placeholder="选择日期" class="width220" /></el-form-item>
        <el-form-item label="上传人"><el-input v-model="dialog.formData.assayerName" disabled class="width220" /></el-form-item>
        <el-form-item class="form-item-block text-center">
          <el-button type="primary" @click="submit()">提交</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>
<script>
import {insertInnerBlood,queryInnerBloodHistoryByHid,updateInnerBlood} from "plugins/axios/inquiryRecord.js"
import api from 'plugins/axios/api.js';
export default {
  props:{
    pid:{
      type:[String,Number]
    },
    providerId:{
      type:[String,Number]
    }
  },
  data(){
    return {
      tableDataForBlood:[],
      dialog:{
        formData:{},
        open:false
      },
      bloodTypeList:[],
      hemoglobinLevelList:[],
      ALTResultList:[]
    }
  },
  created(){
    let self =this;
    api.getCodeDataByCodeType('bloodType').then(res=>{
      self.bloodTypeList=res.content;
    })
    api.getCodeDataByCodeType('hemoglobinLevel').then(res=>{
      self.hemoglobinLevelList=res.content
    })
    api.getCodeDataByCodeType('ALTResult').then(res=>{
      self.ALTResultList=res.content;
    })
    
  },
  mounted(){},
  watch:{},
  computed:{},
  methods:{
    init(){
      this.getQueryInnerBloodHistoryByHid();
    },
    getQueryInnerBloodHistoryByHid(cd){
      let self = this;
      queryInnerBloodHistoryByHid(self.pid).then(res=>{
        self.tableDataForBlood=res.content
        cd&&cd(res.content[0]);
      })
    },
    showDialog(){
      let self = this;
      insertInnerBlood({hid:self.pid}).then(res=>{
        this.getQueryInnerBloodHistoryByHid(content=>{
          this.dialog.open=true;
          this.dialog.formData={...content};
        })
      })
    },
    insertUpdateCheck(row){
      let self=this;
      self.dialog.open=true;
      self.dialog.formData={...row}

    },
    submit(){
      let self = this;
      let postData={
        ...self.dialog.formData
      }
      updateInnerBlood(postData).then(res=>{
        self.dialog.open = false;
        self.$message("保存成功!");
        self.init();
      });
    }
  }
}
</script>
<style scoped>
</style>